﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assessment.Management.SharedComponent.Entities;
using Assessment.Management.SharedComponent.Constants;
using Assessment.Management.SharedComponent.Params.CommonParam;

namespace Assessment.Management.DAO.CommonManagers
{
    public class QuestionDAO : BaseDaos
    {
        public QuestionDAO()
            : base()
        {
        }

        public void GetListQuestion(QuestionParam param)
        {
            string query = "Select * from Questions where Deleted=@Deleted";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@Deleted", SMX.smx_IsNotDeleted);
            try
            {
                param.listQuestion = base.ExecuteQueryGetListObject<Question>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }

        public void GetListQuestionByType(QuestionParam param)
        {
            string query = "Select * from Questions where Deleted=@Deleted and Type=@Type";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@Deleted", SMX.smx_IsNotDeleted);
            cmd.Parameters.AddWithValue("@Type", param.Question.Type);
            try
            {
                param.listQuestion = base.ExecuteQueryGetListObject<Question>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }

        public void GetListQuestionByGroupID(QuestionParam param)
        {
            string query = "Select * from Questions where Deleted=@Deleted and GroupID=@GroupID";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@Deleted", SMX.smx_IsNotDeleted);
            cmd.Parameters.AddWithValue("@GroupID", param.Question.GroupID);
            try
            {
                param.listQuestion = base.ExecuteQueryGetListObject<Question>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }

        public void GetListQuestionByID(QuestionParam param)
        {
            string query = "Select * from Questions where Deleted=@Deleted and ID=@ID";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@Deleted", SMX.smx_IsNotDeleted);
            cmd.Parameters.AddWithValue("@ID", param.Question.ID);
            try
            {
                param.Question = base.ExecuteQueryGetObject<Question>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }
    }
}
